#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <numeric>
#include <ctime>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#define  int long long 
#define endl '\n'
using ll=long long;
using namespace std;

const int N = 2e5 + 5, mod = 1e9 + 7, inf = 2e18;
int n, k, ans;


void solve()
{
    cin >> n;
    vector<ll> a(n),pre_mx,suff_min(n),suff_sum(n+1,0);
    ll mx=0,mi=LLONG_MAX,sum=0;

    for(int i=0;i<n;i++){
    	cin>>a[i];
    	mx=max(mx,a[i]);
    	pre_mx.push_back(mx);
	}
	for(int i=n-1;i>=0;i--){
		mi=min(mi,a[i]);
		suff_min[i]=mi;
	}

	for(int i=n-1;i>=0;i--){
		sum+=a[i];
		suff_sum[n-i]=sum;
	}
	
//	for(auto x:pre_mx)cout<<x<<" ";
//	cout<<endl; 
//	for(auto x:suff_min)cout<<x<<" ";
//	cout<<endl; 
//	for(auto x:suff_sum)cout<<x<<" ";
//	cout<<endl; 
	
	
	vector<ll> ans(n);
	for(int i=1;i<=n;i++){
		ll a=suff_sum[i];
		ll b=LLONG_MIN;
		if(i-1>=0&&n-i-1>=0){
			b=suff_sum[i-1]+pre_mx[n-i-1];
		}
		ans[i-1]=max(a,b);
	} 
	for(auto x:ans)cout<<x<<" ";
	cout<<endl;

	
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }
    return 0;
}
